package com.kyubi.tagger.decorators;

import java.util.Vector;

import sun.security.jca.GetInstance.Instance;

import com.kyubi.common.data.Instances;
import com.kyubi.tagger.ITagger;

/**
 * This class represents the tagger decorator that just caches the results until
 * this decorator.
 * @author anand
 *
 */
public class CachingDecorator implements ITagger {

	private ITagger tagger;
	private Vector<String> original = null;
	private Vector<String> tagged = null;
	private boolean modify = false;
	
	/**
	 * Constructor
	 * @param tagger	the decorated tagger
	 * @param modifyOriginal	variable to switch this decorator on/off
	 */
	public CachingDecorator(ITagger tagger, boolean modifyOriginal) {
		this.tagger = tagger;
		this.modify = modifyOriginal;
	}
	
	/**
	 * @see com.kyubi.tagger.ITagger
	 */
	public Vector<String> getOriginalValues() {
		if(original != null) {
			return original;
		} else {
			if(modify) {
				original = getTaggedValues();
			} else {
				original = tagger.getOriginalValues();
			}
		}
		
		return original;
	}

	/**
	 * @see com.kyubi.tagger.ITagger
	 */
	public Vector<String> getTaggedValues() {
		if(tagged != null) {
			return tagged;
		}
		
		tagged = tagger.getTaggedValues();
		
		return tagged;
	}

}
